{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {
    "id": "0"
   },
   "source": [
    "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gee-community/geemap/blob/master/docs/workshops/FOSS4GNA_2024.ipynb)\n",
    "\n",
    "**Open Source Pipeline to Integrate Drone and Satellite Data**\n",
    "\n",
    "This notebook is designed for workshop presented at the [FOSS4G NA 2024](https://www.foss4gna.org) conference on September 9, 2024. Click the \"Open in Colab\" button above to run this notebook interactively in the cloud.\n",
    "\n",
    "-   Registration: <https://bit.ly/3X1mBi7>\n",
    "-   Notebook: <https://geemap.org/workshops/FOSS4GNA_2024>\n",
    "-   Earth Engine: <https://earthengine.google.com>\n",
    "-   Geemap: <https://geemap.org>\n",
    "-   Leafmap: <https://leafmap.org>\n",
    "-   Data to Science (D2S): <https://ps2.d2s.org>\n",
    "-   D2S Python API: <https://py.d2s.org>\n",
    "  \n",
    "## Acknowledgments\n",
    "\n",
    "This training material was partially supported by the National Agricultural Producers Data Cooperative (USDA award 2023-77039-41033; Sub-award 25-6231-0428-008).\n",
    "\n",
    "## Introduction\n",
    "\n",
    "\n",
    "\n",
    "Recent advances in drone technology have revolutionized the remote sensing community by providing means to collect fine spatial and high temporal resolutions at affordable costs. As people are gaining access to increasingly larger volumes of drone and satellite geospatial data products, there is a growing need to extract relevant information from the vast amount of freely available geospatial data. However, the lack of specialized software packages tailored for processing such data makes it challenging to develop transdisciplinary research collaboration around them. This workshop aims to bridge the gap between big geospatial data and research scientists by providing training on an open-source online platform for managing big drone data known as Data to Science. Additionally, attendees will be introduced to powerful Python packages, namely Geemap and Leafmap, designed for the seamless integration and analysis of drone and satellite images in various applications. By participating in this workshop, attendees will acquire the skills necessary to efficiently search, visualize, and analyze geospatial data within a Jupyter environment, even with minimal coding experience. The workshop provides a hands-on learning experience through practical examples and interactive exercises, enabling participants to enhance their proficiency and gain valuable insights into leveraging geospatial data for various research purposes.\n",
    "\n",
    "### Prerequisites\n",
    "\n",
    "-   To use geemap and the Earth Engine Python API, you must [register](https://code.earthengine.google.com/register) for an Earth Engine account and follow the instructions [here](https://docs.google.com/document/d/1ZGSmrNm6_baqd8CHt33kIBWOlvkh-HLr46bODgJN1h0/edit?usp=sharing) to create a Cloud Project. Earth Engine is free for [noncommercial and research use](https://earthengine.google.com/noncommercial). To test whether you can use authenticate the Earth Engine Python API, please run [this notebook](https://colab.research.google.com/github/gee-community/geemap/blob/master/docs/notebooks/geemap_colab.ipynb) on Google Colab.\n",
    "\n",
    "-   It is recommended that attendees have a basic understanding of Python and Jupyter Notebook.\n",
    "-   Familiarity with the Earth Engine JavaScript API is not required but will be helpful.\n",
    "-   Attendees can use Google Colab to follow this short course without installing anything on their computer.\n",
    "\n",
    "### Agenda\n",
    "\n",
    "The main topics to be covered in this workshop include:\n",
    "\n",
    "* Create interactive maps\n",
    "* Visualize drone imagery from D2S\n",
    "* Visualize Earth Engine data\n",
    "* Explore Earth Engine Data Catalogs\n",
    "* Analyze Earth Engine data\n",
    "* Create timelapse animations\n",
    "\n",
    "\n",
    "## Introduction to Earth Engine and geemap\n",
    "\n",
    "Earth Engine is free for [noncommercial and research use](https://earthengine.google.com/noncommercial). For more than a decade, Earth Engine has enabled planetary-scale Earth data science and analysis by nonprofit organizations, research scientists, and other impact users.\n",
    "\n",
    "With the launch of Earth Engine for [commercial use](https://earthengine.google.com/commercial), commercial customers will be charged for Earth Engine services. However, Earth Engine will remain free of charge for noncommercial use and research projects. Nonprofit organizations, academic institutions, educators, news media, Indigenous governments, and government researchers are eligible to use Earth Engine free of charge, just as they have done for over a decade.\n",
    "\n",
    "The geemap Python package is built upon the Earth Engine Python API and open-source mapping libraries. It allows Earth Engine users to interactively manipulate, analyze, and visualize geospatial big data in a Jupyter environment. Since its creation in April 2020, geemap has received over 3,400 GitHub stars and is being used by over 3,000 projects on GitHub.\n",
    "\n",
    "## Google Colab and Earth Engine Python API authentication\n",
    "\n",
    "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gee-community/geemap/blob/master/docs/workshops/FOSS4GNA_2024.ipynb)\n",
    "\n",
    "### Change Colab dark theme\n",
    "\n",
    "Currently, ipywidgets does not work well with Colab dark theme. Some of the geemap widgets may not display properly in Colab dark theme.It is recommended that you change Colab to the light theme.\n",
    "\n",
    "![](https://i.imgur.com/EJ0GDP8.png)\n",
    "\n",
    "\n",
    "### Install geemap\n",
    "\n",
    "The geemap package is pre-installed in Google Colab and is updated to the latest minor or major release every few weeks. Some optional dependencies of geemap being used by this notebook are not pre-installed in Colab. Uncomment the following code block to install geemap and some optional dependencies."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "1",
    "outputId": "873b037a-7164-47d7-b12b-32e8ce450d9a"
   },
   "outputs": [],
   "source": [
    "# %pip install -U \"geemap[workshop]\" leafmap d2spy"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3",
   "metadata": {
    "id": "2"
   },
   "source": [
    "Note that some geemap features may not work properly in the Google Colab environmennt. If you are familiar with [Anaconda](https://www.anaconda.com/download) or [Miniconda](https://docs.anaconda.com/free/miniconda), it is recommended to create a new conda environment to install geemap and its optional dependencies on your local computer.\n",
    "\n",
    "```bash\n",
    "conda create -n gee python=3.11\n",
    "conda activate gee\n",
    "conda install -c conda-forge mamba\n",
    "mamba install -c conda-forge geemap pygis\n",
    "pip install d2spy\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4",
   "metadata": {
    "id": "3"
   },
   "source": [
    "### Import libraries\n",
    "\n",
    "Import the necessary libraries for this workshop."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5",
   "metadata": {
    "id": "4"
   },
   "outputs": [],
   "source": [
    "import ee\n",
    "import geemap\n",
    "import leafmap"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6",
   "metadata": {
    "id": "5"
   },
   "source": [
    "### Authenticate and initialize Earth Engine\n",
    "\n",
    "You will need to create a [Google Cloud Project](https://console.cloud.google.com/projectcreate) and enable the [Earth Engine API](https://console.cloud.google.com/apis/api/earthengine.googleapis.com) for the project. You can find detailed instructions [here](https://book.geemap.org/chapters/01_introduction.html#earth-engine-authentication).\n",
    "\n",
    "Login to Earth Engine JavaScript Code Editor at [https://code.earthengine.google.com](https://code.earthengine.google.com) and click on th profile icon at the top right. Remember the project ID listed in the dialog that appears. Uncomment the following code block and replace `YOUR_PROJECT_ID` with your project ID."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 17
    },
    "id": "6",
    "outputId": "b66bbad2-6eb8-4b6f-9363-297402bd1d24"
   },
   "outputs": [],
   "source": [
    "# os.environ[\"EE_PROJECT_ID\"] = \"YOUR-PROJECT-ID\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8",
   "metadata": {
    "id": "7"
   },
   "source": [
    "Then, run the code block to authenticate and initialize the Earth Engine Python API."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 17
    },
    "id": "8",
    "outputId": "d1a1e36f-4d64-4d34-a857-6986ed02e0c4"
   },
   "outputs": [],
   "source": [
    "geemap.ee_initialize(project=None)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10",
   "metadata": {
    "id": "9"
   },
   "source": [
    "## Creating interactive maps\n",
    "\n",
    "Let's create an interactive map using the `ipyleaflet` plotting backend. The [`geemap.Map`](https://geemap.org/geemap/#geemap.geemap.m) class inherits the [`ipyleaflet.Map`](https://ipyleaflet.readthedocs.io/en/latest/map_and_basemaps/map.html) class. Therefore, you can use the same syntax to create an interactive map as you would with `ipyleaflet.Map`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 17
    },
    "id": "10",
    "outputId": "7631fd4d-20c1-4ec8-817b-beb9fbf97a85"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12",
   "metadata": {
    "id": "11"
   },
   "source": [
    "To display it in a Jupyter notebook, simply ask for the object representation:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 621,
     "referenced_widgets": [
      "3ce3481354af40b687866d7ea44bd343",
      "0152770d6cbc4c8eb08fed7b6ff4e9df",
      "2c53a33383264465a3a4cdca61e93b36",
      "d89f74dd252745ed950ef00ec58fdce4",
      "c743ddd759974fa087ff8e36e391fb38",
      "419d3608ba734a67aa4e9f08c77048e5",
      "02882ccc762f4698a268a7f62a923387",
      "75ff0d83c6db494eac2db7d244b0c406",
      "672f71522ce54a179ad3229683d800da",
      "3e1dfaee392644d1a510b9a9a75c0b90",
      "cf23767414f04cbda4dfa1b0c0fdd806",
      "b072b10344a248f4ab2412631162e707",
      "f5bbd821643c4e508a4b7ed332272dfc",
      "118e24f23dd643a7a1474cec39f16ad1",
      "3aceb0f48c204e0caf4215e5b8b1b08d",
      "d1d7120e2f52431681fd382020c02d40",
      "aab80a2f604d45439b46ba8db44bc266",
      "18c961691e3f449398e85829c17bf125",
      "4eb4961ca36a4532876a2c9468911870",
      "aeb4a0b3b39747ab866a16b7969fd049",
      "44bbc16caad3454c8022627866926446",
      "dbdff4a3ab9040b69c1cdfe152b11ffa",
      "9a35ce33d6cc4e939b5afeab05fb35a6",
      "0e56a5db98b94102b95c887457438cc5",
      "80945aa12cba4e859d96612caf7a74ec",
      "31a822a5dff540b6928ba431a1386216",
      "d6d9f2be98114a58aab216f76441603e",
      "7de028b09a5b4a0a9adc1affc7391858",
      "3c84fb3544344cfca79279c85b65fe1a",
      "fb2e1adbf6d14b30a6d7328d628a4bc0",
      "90f55027bf854fd8a0e264be41604543",
      "27ba891d2cbb4ce68d333ce5623aeb99",
      "d41fe0380a1a4f07a09ce8f6ed12eda0",
      "8cd4a60b66d84a6b9a3f076ba68af15a",
      "3778c4cf52df4b92b5e2a63532b6faca",
      "678f7e227ac54c98ab2b214de4f0e754",
      "891c6a62d74f4643ae06e285a719db2f",
      "cfa5c1530b37455bbdd4a1081cb42382",
      "65a2ce9be57444d99cbc34b1bf55d329",
      "6effc54320b049418c2a62f2c5967769",
      "3cbe7b3c66644c86af037c0de6b46c55",
      "edfc12a87e5a420b8de12f1f2a61db53",
      "26f953612813413380aa5f7eff7a6d41",
      "c0e3cf2ab1874b1fbee74249063dfbe1",
      "03aa0eb19c4b4232858134afe3f612de",
      "787180144b8e4c7284cf3c258cb68925",
      "e6cbb1359207489cbcf3565e8e348b11",
      "04d62c2ead5547099e4c774f614db44e",
      "1daa6fa4772840b6a9a5b0a7c6056c96",
      "59224fd6aaf84a18a5e32bd1461c615f",
      "3e20a17c9721475394bf2470da76560d",
      "c5494e4fd53840eeb5bfb25e722a86ab",
      "e2a0711eb22e4d76b6f3d6ae94f7ea04",
      "3ab9e189e1c045caa429029002395e93",
      "77aedf2f8a024dc38591348edc51368b",
      "19c9b05bda594cc78843396102036cf0",
      "af96252711154291bb04a6cf2b33bae9",
      "ed362eecaeec4e37886aef4c19953680",
      "e60150e0a5b1449db5bb995d4486ef44",
      "926fb188ea24475da5f2c440a3efc463",
      "7b1e6d43513f433cb9e5af63d9657d8c"
     ]
    },
    "id": "12",
    "outputId": "f7f487c9-b2b0-4da5-f694-4f7163171431"
   },
   "outputs": [],
   "source": [
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14",
   "metadata": {
    "id": "13"
   },
   "source": [
    "To customize the map, you can specify various keyword arguments, such as `center` ([lat, lon]), `zoom`, `width`, and `height`. The default `width` is `100%`, which takes up the entire cell width of the Jupyter notebook. The `height` argument accepts a number or a string. If a number is provided, it represents the height of the map in pixels. If a string is provided, the string must be in the format of a number followed by `px`, e.g., `600px`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15",
   "metadata": {
    "colab": {
     "referenced_widgets": [
      "9b24f7ca54b441d7a0a5bd101ffd6657"
     ]
    },
    "id": "14",
    "outputId": "6242756a-969b-4551-a868-a481799c554e"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map(center=[40, -100], zoom=4, height=\"600px\")\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "16",
   "metadata": {
    "id": "15"
   },
   "source": [
    "To hide a control, set `control_name` to `False`, e.g., `draw_ctrl=False`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17",
   "metadata": {
    "id": "16"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map(data_ctrl=False, toolbar_ctrl=False, draw_ctrl=False)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18",
   "metadata": {
    "id": "17"
   },
   "source": [
    "### Adding basemaps\n",
    "\n",
    "There are several ways to add basemaps to a map. You can specify the basemap to use in the `basemap` keyword argument when creating the map. Alternatively, you can add basemap layers to the map using the `add_basemap` method. Geemap has hundreds of built-in basemaps available that can be easily added to the map with only one line of code.\n",
    "\n",
    "Create a map by specifying the basemap to use as follows. For example, the `Esri.WorldImagery` basemap represents the Esri world imagery basemap."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19",
   "metadata": {
    "colab": {
     "referenced_widgets": [
      "ec42c6d324864710ae1296df1cd231c3"
     ]
    },
    "id": "18",
    "outputId": "3e8b302b-a230-4543-bcdf-d858c1c3134f"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map(basemap=\"Esri.WorldImagery\")\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "20",
   "metadata": {
    "id": "19"
   },
   "source": [
    "You can add as many basemaps as you like to the map. For example, the following code adds the `OpenTopoMap` basemap to the map above:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21",
   "metadata": {
    "id": "20",
    "outputId": "b1fea60d-6a8c-4c9e-fc13-0e3525c4a917"
   },
   "outputs": [],
   "source": [
    "m.add_basemap(\"OpenTopoMap\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "22",
   "metadata": {
    "id": "21"
   },
   "source": [
    "You can also add an XYZ tile layer to the map."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "23",
   "metadata": {
    "id": "22",
    "outputId": "c4f2108b-8a2b-4903-db1a-bcc0690a3651"
   },
   "outputs": [],
   "source": [
    "basemap_url = \"https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}\"\n",
    "m.add_tile_layer(basemap_url, name=\"Hybrid\", attribution=\"Google\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "24",
   "metadata": {
    "id": "23"
   },
   "source": [
    "You can also change basemaps interactively using the basemap GUI."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25",
   "metadata": {
    "colab": {
     "referenced_widgets": [
      "5b21e67fb214433f9fbf479a05029bfb"
     ]
    },
    "id": "24",
    "outputId": "2026d34d-9800-4db5-b8e7-88576ff50dc3"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "m.add(\"basemap_selector\")\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26",
   "metadata": {
    "id": "25"
   },
   "source": [
    "## Visualizing Drone Imagery from D2S\n",
    "\n",
    "The Data to Science (D2S) platform (https://ps2.d2s.org) hosts a large collection of drone imagery that can be accessed through the D2S API (https://py.d2s.org). To visualize drone imagery from D2S, you need to [sign up](https://ps2.d2s.org/auth/register) for a free account on the D2S platform and obtain an API key. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27",
   "metadata": {
    "id": "777eee44-ffd2-4dbf-a614-c857e18c1f56"
   },
   "source": [
    "### Login method #1\n",
    "Login procedure using d2spy Auth module."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "28",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 51
    },
    "id": "26",
    "outputId": "01931306-0bd4-4f14-e9cd-455c5b4182ea"
   },
   "outputs": [],
   "source": [
    "from d2spy.auth import Auth\n",
    "from d2spy.workspace import Workspace\n",
    "\n",
    "# Replace with URL to a D2S instance\n",
    "d2s_url = \"https://ps2.d2s.org\"\n",
    "\n",
    "# Login with your email address\n",
    "auth = Auth(d2s_url)\n",
    "auth.login(email=\"workshop@d2s.org\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "29",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 17
    },
    "id": "Ii9l-5KsWSaK",
    "outputId": "34a6b971-8f0d-4efd-f737-156dc02762ce"
   },
   "outputs": [],
   "source": [
    "# Check for API key\n",
    "user = auth.get_current_user()\n",
    "api_key = user.api_access_token\n",
    "if not api_key:\n",
    "    print(\n",
    "        \"No API key. Please request one from the D2S profile page and re-run this cell.\"\n",
    "    )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "30",
   "metadata": {
    "id": "de1a9ee4-d27e-49cb-9dcf-db32aab48ccc"
   },
   "source": [
    "### Login method #2\n",
    "Login and connect to your D2S workspace in one go using the d2spy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "31",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "id": "8d07e871-f795-4022-8e31-4e5a480cb1e1",
    "outputId": "de330548-84f4-4310-c9e1-d03642cecab1"
   },
   "outputs": [],
   "source": [
    "from d2spy.workspace import Workspace\n",
    "\n",
    "# Replace with URL to a D2S instance\n",
    "d2s_url = \"https://ps2.d2s.org\"\n",
    "\n",
    "# Login and connect to workspace with your email address\n",
    "workspace = Workspace.connect(d2s_url, \"workshop@d2s.org\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 17
    },
    "id": "baf2b4d6-8945-4fbc-8429-776c069c918c",
    "outputId": "3477504a-f287-4df6-a10c-edf34d6479b9"
   },
   "outputs": [],
   "source": [
    "# Check for API key\n",
    "api_key = workspace.api_key\n",
    "if not api_key:\n",
    "    print(\n",
    "        \"No API key. Please request one from the D2S profile page and re-run this cell.\"\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 17
    },
    "id": "T_4tyKQJWWk1",
    "outputId": "9919c432-af9a-4230-8553-e6d23cad9588"
   },
   "outputs": [],
   "source": [
    "import os\n",
    "from datetime import date\n",
    "\n",
    "os.environ[\"D2S_API_KEY\"] = api_key"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34",
   "metadata": {
    "id": "TOx4ytjZKLOC"
   },
   "source": [
    "## Choosing a project to work with\n",
    "\n",
    "The Workspace `get_projects` method will retrieve a collection of the projects your account can currently access on the D2S instance."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "35",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 17
    },
    "id": "n7EY09rXKdHC",
    "outputId": "058b3d00-0341-4947-e1e1-364e0d3c0bac"
   },
   "outputs": [],
   "source": [
    "# Workspace session (Uncomment below line if using Login Method #1)\n",
    "# workspace = Workspace(d2s_url, auth.session)\n",
    "\n",
    "# Get list of all your projects\n",
    "projects = workspace.get_projects()\n",
    "projects"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "36",
   "metadata": {
    "id": "zTQJkyxaKxKn"
   },
   "source": [
    "The `projects` variable is a `ProjectCollection`. The collection can be filtered by either the project descriptions or titles using the methods `filter_by_title` or `filter_by_name`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "id": "eXVGv5WBK_VH",
    "outputId": "3ac9762b-46e3-44cf-c7a4-2e1f2afa6491"
   },
   "outputs": [],
   "source": [
    "# Example of creating new collection of only projects with the keyword \"Test\" in the title\n",
    "filtered_projects = projects.filter_by_title(\"Purdue\")\n",
    "print(filtered_projects)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "38",
   "metadata": {
    "id": "O6fdeffmLIN5"
   },
   "source": [
    "Now you can choose a specific project to work with. In this case, the filtered projects returned only one project, so we will use that project."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 17
    },
    "id": "UMvUAPQPLQYK",
    "outputId": "8c212b2e-bc48-45f3-b654-f02dd442400d"
   },
   "outputs": [],
   "source": [
    "project = filtered_projects[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40",
   "metadata": {
    "id": "yqo000pqLYn4"
   },
   "source": [
    "`get_project_boundary` method of the `Project` class will retrieve a GeoJSON object of the project boundary."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "41",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 54
    },
    "id": "StEMiRfJLXWX",
    "outputId": "07f9a7f3-b112-41b6-abd3-97cf3ee309f7"
   },
   "outputs": [],
   "source": [
    "# Get project boundary as Python dictionary in GeoJSON structure\n",
    "project_boundary = project.get_project_boundary()\n",
    "print(project_boundary)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42",
   "metadata": {
    "id": "OvFhMBNtLv9X"
   },
   "source": [
    "The `Project` `get_flights` method will retrieve a list of flights associated with the project."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 88
    },
    "id": "mdWpH7N2L9eN",
    "outputId": "d336fb5d-c463-450e-b3ed-9466a04476e9"
   },
   "outputs": [],
   "source": [
    "# Get list of all flights for a project\n",
    "flights = project.get_flights()\n",
    "# Print first flight object (if one exists)\n",
    "for flight in flights:\n",
    "    print(flight)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "44",
   "metadata": {
    "id": "eT8rrteTMM4z"
   },
   "source": [
    "The `flights` variable is a `FlightCollection`. The collection can be filtered by the acquisition date using the method `filter_by_date`. This method will return all flights with an acquisition date between the provided start and end dates."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 71
    },
    "id": "urXu65AsMfk0",
    "outputId": "8e89d7e5-7621-4b30-a200-3ced37e65f95"
   },
   "outputs": [],
   "source": [
    "# Example of creating new collection of only flights from Jan 2015 - Dec 2024\n",
    "filtered_flights = flights.filter_by_date(\n",
    "    start_date=date(2015, 1, 1), end_date=date(2024, 12, 31)\n",
    ")\n",
    "for flight in filtered_flights:\n",
    "    print(flight)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46",
   "metadata": {
    "id": "dOlbqBhRNX4e"
   },
   "source": [
    "Now, we can choose a flight from the filtered flight. Let's choose the 2018 flight."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 17
    },
    "id": "afjCXq05NW_t",
    "outputId": "9b45bca9-04c3-41f3-e281-fee2df318122"
   },
   "outputs": [],
   "source": [
    "flight = filtered_flights[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48",
   "metadata": {
    "id": "ngIYB3tANljF"
   },
   "source": [
    "The Flight `get_data_products` method will retrieve a list of data products associated with the flight."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "49",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 122
    },
    "id": "iRQEODHXNrBL",
    "outputId": "4c5e1c7c-4224-4b8f-98bc-3e4dedef5e4a"
   },
   "outputs": [],
   "source": [
    "# Get list of data products from a flight\n",
    "data_products = flight.get_data_products()\n",
    "\n",
    "for data_product in data_products:\n",
    "    print(data_product)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "50",
   "metadata": {
    "id": "yiKBMsv7N4cy"
   },
   "source": [
    "The `data_products` variable is a `DataProductCollection`. The collection can be filtered by data type using the method `filter_by_data_type`. This method will return all data products that match the requested data type."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 54
    },
    "id": "zL-u2UtUN3zc",
    "outputId": "5b494975-2937-4954-b0b1-98671f1db47c"
   },
   "outputs": [],
   "source": [
    "# Example of creating new collection of data products with the \"ortho\" data type\n",
    "ortho_data_products = data_products.filter_by_data_type(\"ortho\")\n",
    "print(ortho_data_products)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "52",
   "metadata": {
    "id": "ZryOKEuROOnu"
   },
   "source": [
    "Now we can grab the ortho URL to display it using geemap."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "53",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 621,
     "referenced_widgets": [
      "f2984092efaf4a2e9f6b95cc75bc529b",
      "15adc779e7594d74b03d00bda6436c80",
      "128335ec2b98495ab9b3ab44ee980ca7",
      "c0d277ef133c40e9b52e1a3135ee7845",
      "70e52d45144c49898e8b1a0c3a80c3f6",
      "f14ae495547b4faeb99cbe5fcd1a28f1",
      "a4c05727c0704772ab916d21b785bd21",
      "e0f9eda71f944935b45d38e54a33a344",
      "32ae5b522ac340149c02a8b65019a8a1",
      "e3f3e67cb1ba4b05a5261cace7cba5d1",
      "d351aadc276446c2952226da2e63ad4a",
      "8c56b07967244c409ed02f20caa5777a",
      "024079c8936b47128caa352f4a3abc9b",
      "41e49b5ff9764ec3b94b1b80e228e700",
      "ca7059ea48b64915a328d565b1fa6208",
      "271220f67d3a40dd8d3b992fbaf390bf",
      "6ccadd6ecdb0454c814cc38c00235ce2",
      "54f9a24eeb794b10bc2bffc051f9a916",
      "d602a4793fad417e9b899c8facae9821",
      "5078ada7657c42d0a804861cc0bd9042",
      "0d1f6ef6420f4c38a6fa6ac01fb0fe11",
      "febfc4eb09c744f79f29b1f015645e80",
      "cf893914bcfd4f3189bec464e25ba452",
      "7c4516f027554ec78ec21894825ae58b",
      "de496c7f3c5b4143b5388003d7996bc7",
      "86dcde7e21d1427f83d828a9f92e8a3a",
      "aa78bd4e96aa4c72a92a830163b876f2",
      "1c19c170c3fe4d25a15c2452e3c8a822",
      "b378a2a6435e44f8875f230db3556698",
      "1d15879b13b54b7b8b55eb50431c4acd",
      "65523187ad17480f87f23711c1884d0c",
      "afda6b13aac845c68b24e841add570cd",
      "80050c8c67214bea9d0070ae6bcc3e19",
      "86c1a9c7707947e9915972b3e8905da6",
      "4ecf5fdaf448480881c7eeebee30c824",
      "330bc30a5fa54f53bf4c0447204289de",
      "5a2fa365c0e242fa8c4b4b50db8c8c96",
      "1da0b11509a242c790caba45fce29508",
      "9a465a7605eb4c1d904b8903cae7c8b1",
      "a7454ad6c936437ca93828efc66c796b",
      "5ebe4e16a52341459ae368b06f8ddebe",
      "72377a44291d49c282b8b6c6796975a9",
      "9f4ea46c9b8c4dbe91dd2a4177ffcd85",
      "187b1aaef9b2468c81ece4593f424944",
      "d496a8152dbc48acab5bb64d96f8d6d5",
      "9d201f53956840389cd7c2d2c4619ec1",
      "8ca9814771e74a4f96592ef7c67afe23",
      "17fad8d0b3f0400fbfc4f9d95cc96052",
      "46969d4c38df4dc682f94f26f8c587b6",
      "d1c0323663714ca79a7c374622d7cfb5",
      "6b030575c40c46b0899c473e0929101c",
      "ee8bf9f2412d40a6a1025c8ab1539401",
      "c568b4c886f54bb39f79436591745e13",
      "fa089dab26204b13b8f15bee49ec9f5a",
      "082c19e8c1894dd18f011516ca4b7d9e",
      "bbe749f4e5e64a9892e1e8fa3714972c",
      "edcf58e3242840b49a7ca3a2548cd3c6",
      "4342ce4c74004d0ba6eb2598ccb21d58",
      "68d46b1c66a7459881b4e99ed7a1f1a7",
      "70e86a0772c045b38a8b6a1cf59348ff",
      "15e8a6e9a09f4cdebf480d4713b2dc83",
      "125b802d601b43fa825d89a27fc4d6ac",
      "c0c2b926d3bf43d2ab35cdfa26e0190a",
      "d2806c4bdf164d85be53cb29867fe4fd",
      "89e16c5fe72644b58b549048fe52b15a",
      "8d2a2e95b63a4db08ffdcbfab33d0290",
      "b3807a7e3c734bb6bf392c0a50cc0915",
      "62f2f006846b47cfa4d4321d8625e20f",
      "eae3369d8ebb4e5e8b7006ade41bc9d3",
      "24f1ba96905945078310633991f8d012",
      "db681190a5d44c1bb510f82d172d31ee",
      "0278bcbad3a4453c8eb22f90821db861",
      "7ae078313291408287c593ed3e68fe12",
      "04e536ecf81d48fa93ebd3ea5ca6ef4d",
      "c40d60bf5e164a29b3442dae615274c5",
      "ea9c429b3a2f49138df860f8f905e8b5",
      "19db6c55f90845ffb9889262fc2a923d",
      "e29f2cb73ff740c4b66aef933d951d21",
      "9876b9900a9c4628b21ce7d6234c9285",
      "a67eb2dab5504cfc9e9fafdc4ee9967d",
      "6a512e68c9f74cb2952521d12fc75a6c",
      "0bb05483a007415786a85f22e2976b2b",
      "b4c6bff92f0e45859128cb19a0d13cbf",
      "8960e0aaa8b54bfb98c82a59f161e9d9",
      "7c640255771545c7b11eff15e3e93fd9",
      "540d70d10bcb42bf9de285a7b7803eea",
      "25ccfc0acbf947f0bdc5dda077b79db7",
      "8c03baf94113412f9e87a02406b3ce32",
      "cebc6bfe0fde42cd9c74f77578b49378",
      "c3c9e6b39a8244a58226ad556f65afea",
      "e765cacaf73d41b8a0017d61d5a15a8e",
      "01b0eee7a0414f99a7916244ac07c164",
      "420b65dc4ebb42da8e27ef1dd307fa5c",
      "21c72aa4c9db4fa2abd2b9a2c377758c",
      "ddceb48c53c84460af51b41e376019ee",
      "89ee25b60f4c48e0b377b05e875fd07f",
      "7488f1cab94e46119807262ec5b8eb31",
      "f20c3c478d6f446eb769679b9ec1c388",
      "bf8f052252c94dacb7a80d1b79941b09",
      "7e3f93be1f7247788474689f7f15e29e",
      "7f9396c12dc34c45b5bbd8308d3c0860",
      "2e1aa45581ea4b55b8781d563048b4af",
      "cb7c6debd3a1440196f9f529d3c83510",
      "283b4bf17013478e80381bc4ce93ba52",
      "39eb00b6f04648b4ab173eb17b92e872",
      "dc2a5a1cb8184f1dbf37c6d5397cff4b",
      "4b4bcfb9734b46b482778dc63b958955",
      "29cc010bd2444f31a7ee48e17658660e",
      "563799e1ec8a44698c1f80558690a6ad",
      "31abed0389b84a8f87022633a170e64e",
      "9d12c2cd39f94fb695c1e73936a80d5a",
      "1046d7ef7d1a4a79ace5f9ed24d1fceb",
      "9678e8a746f74ebbae830c2a9aa068d5",
      "5187d5ef83cd426ea1fc2c02fb791731",
      "4fac5ce83f9e4dfca51e66922e810fe6",
      "4d2dd58b9fca4faf99225a89200cee95",
      "cbe564ab4e6442d78c49c9516299b43c",
      "a198f435dfa843e8bbbf426695eea322",
      "bf560341680142ae9507f0029ca1faa4",
      "b64b443d7a824cb5b457725336fc0e39",
      "4aed72b3684c4489a6f2a4ac29e35881",
      "9c7f6501253048b7afe49d8dbcf71a12",
      "077498f55675418da971d6ffc3383af5",
      "fbac29e902e644adbbd37101aff62988",
      "624a1a2c9b2443f299fe973780c0ae21",
      "5531f19d064946e488383c7e80a1f6c8",
      "56de561b6c5b486cb0ab31bd09e74597",
      "ed9cfe85ad6a4245a10d45514e71c2cf",
      "5124215bc2df48b69752d163c087c6e5",
      "c5e6ad8d28db41e792858f04edfbac85",
      "51a45cba453c46e99550174de4ff6512",
      "a6b5730fa0cc4d669baccebe9071f079",
      "f7a89550fbf646d8bd7b0ce27b317e24",
      "0cec46d2c1ff4315b0b5863a55560a62",
      "422c9689934f448fa459bacae75408fd",
      "2815e2c639c247d48968f82ba759095f",
      "e96e2e964fd94aaab967ab6f3493a0f8",
      "3be3a105ca2b469d85390487b0c5dbd3",
      "5bc09233ef76447daf3acc40b18fce76",
      "b961a7f9d2a543e89a0b69aefd903274",
      "4204e1d686d444e0ad906e1a78a90f2f",
      "0b219daa25924bc5aa3e3bc816f95459",
      "6267b86c52e64a248111b755e788820b",
      "31780b13c9a840c6a537c11630b355bb",
      "f9609d915d54430b80786150b4f533da",
      "ee23f2fae3ff483ea0a405ef4886f177",
      "04d47ccac62442518b7a063ecfeb9230",
      "611c5d3463bf4fc2b0f51a4d3b79039c",
      "45671cb31f8a4304938d981c2f887569",
      "c019f799d3e7408786d37ee83de85144",
      "cb32930cacd74e3ba822939bd56139c1",
      "ef05bd1eeb84445a9daf05c481fd2412",
      "fbf0b7bfe3cb4661adf4fc253dcbc63a",
      "dfa907ac9e6e4c59955c9ddec0486d09",
      "af565edc3d1f4e0fae9b627e4d7c3232",
      "988fee3ffff243bbb46a8673c51a88a6",
      "a38f035509844fa6aee59a37b28fb19f",
      "70c534e579d944839aaf268379f6c9ea",
      "72c93de3f7b54ed58efe82e03584b689",
      "21865bb3a3504bba9a6cd5ac6444a5f0",
      "5933772fb3934166816e64a8f9d33077",
      "38da2dd8543b4bdd99e1bd2ec2bfa52e",
      "f7c4c1e620844979a1cb3d7a3be7accd",
      "8a686c889b564023a21b6e14647a20a5",
      "63fec2911ef04a80a22b492b837e8d24",
      "70f555618ded483ab1d9b678d1761b0f",
      "128c32b424a6412481032b7fc2df7d64",
      "859f8224a374460d8156e2593005666e",
      "9d258afbcdad48ed9699797f93ffb855",
      "4c30afd9f2044544b00328c456a894ab",
      "697d7064fc4940958c815960ac4fb8f8",
      "7829e66408a44b8387ccd6cc823f2a64",
      "1e051871ca064eccb0af6cb7cf6e42ed",
      "72dc0cecdd834fe19622beba327900f5",
      "b603d08da95c4a11adcede410e31b8a1",
      "f42ec862c505451d999ea6c9019306c3",
      "2c1cddbde9064608974828644ce75060",
      "9928d5c2a6124ac2a3c88e51433ad18b",
      "f1a9eb0638df4453a1e63fa8cfc93e84",
      "4aebec45b6f440fe9a8decea13eb2b1b",
      "b4d51e60edb646f194c8b9264874243b",
      "cc6121c5edfc4193a612f1d1a410ddec",
      "d881a085cd84427d8db4f6fa4ac88097",
      "d98ee87b679f4bbca76ef7a153dcd7ab",
      "0378aa2147b14405ae21bed8fb5861ad",
      "738d05a21c244a65bc12ce2a3bc9b7f5",
      "533b6898b8504fe59e8efded708e2f2e",
      "7b852bee94134d30838c520cdc217292",
      "78bae3dcd7bf411fb1cdcd62c9e50d6a",
      "d0595c10d6e746bfbfac99a5df606482",
      "5656abb6e07f4230a3aef3117ba96c02",
      "1bd8856af16a4e1ba2ff65e5f326858b",
      "0c7bc2df69bb4a149032e92e683de6b0",
      "e8d9547849244a989667f44b4b16ec59",
      "38e9851e9cac46e9bec8eac8d7d6079c",
      "1a6b5296a55a4209ae356c012248a74b",
      "cf899c76d96d4563b99b2198717dbebe",
      "b8a4286b632e4aefb7a41152e4aac843",
      "210fad450d97415e9501a055e3cd3f36",
      "f980b50491ec4b03a7fe15d7e0e8ddfa",
      "796512c258054bc79998319ce97d5c43",
      "2f810df4d85840fc8e30bb848c1724d9",
      "86b5d39a6e294dcc970b7d568df5a18f",
      "e818ce3fa21346719d19e93a8b4eca58",
      "5fd5d4617a324a0fa0a1a53c117e7dbd",
      "5137d297dd3d4c65ae265e12dae594fa",
      "02f7b1c9cc3542b5a281c404218c4aa4",
      "cd7e3586a46e48bc8936175f97239ce7",
      "906ee10ca27e47cdb698726ad1279bf1",
      "bacffb4c8c284b73aaca916773cd3f62",
      "6cda5c3d83144095ad7da41a55cd55ca",
      "e276504e235a48c88fa2342c7d3b201a",
      "e8d3b549372f42dd8c1d41aa571187b4",
      "d9a78b8cc6494cd2844ec4d2ab793f70",
      "335b8c719c7d480f9b59f213c74502f7",
      "4b748b6bfca34745b8d114777c6057bd",
      "1edf0f9722a4427aa5a54a1c694510fe",
      "c2231040810849cb82b6c3aed144cb5b",
      "e05a68d93385427d913aa452f0d25882",
      "1ff448da9ba54da0a7ba62f84f995925",
      "d8e6dc605268453e8a63d57211a674aa",
      "d04a8789b24c42c0b318126fef4c9c3c",
      "ad7108e9ef734c4194a212afe0926a21",
      "694587a3b84d4f44b288eb9cbb9b22d5",
      "e70fdeb5c84544c8b133d036c18b449b",
      "4dd94e0e04ba4eca8da8c3bbc9d27334",
      "059d04e9e5d3443f93c92dbcacb9e1dd",
      "0a7ee997af254a06804b5273e88257e6",
      "a5cb5563852a45a09b1a81f17bd1ac7d",
      "85e8aec6bffe432f8023069c267eaa40",
      "54d4c544d0fc4a988db8d4649bdb872f",
      "d2db5c41b9cf4f95b66251b3efa13a0b",
      "692682f4b2fc4b56a1fc9596fbd3b8eb",
      "a7e33d106ff945ea8e52b2a2bb7a7d99",
      "284f1ebaee5140b4af0f1db0a1f17fd0",
      "56476d06ba704e3faf40a90bf4191a86",
      "bf3e70be0abe449d82a7b5ccea1d6e32",
      "657853a5f5e54783b713cba3384c616e",
      "f18b2852188945beb99d82ce3f48ae40",
      "2599ff303d4e4d64af6cc6344a0a93c0",
      "95e7c0f8dabf4eefb90e5ca9d5731bb6"
     ]
    },
    "id": "32",
    "outputId": "80d05f04-f255-4f28-fd07-214066197693"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "basemap_url = \"https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}\"\n",
    "m.add_tile_layer(basemap_url, name=\"Google Hybrid\", attribution=\"Google\", shown=False)\n",
    "ortho_data = ortho_data_products[0]\n",
    "ortho_url = ortho_data.url\n",
    "ortho_url = leafmap.d2s_tile(ortho_url)\n",
    "m.add_cog_layer(ortho_url, name=\"RGB Imagery\")\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54",
   "metadata": {
    "id": "33"
   },
   "source": [
    "Similarly, you can visualize the Digital Surface Model (DSM) from D2S using the code below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "55",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 54
    },
    "id": "OBD_vwvuPseQ",
    "outputId": "8e6e8fbb-ad1a-4444-c641-b2b102d72659"
   },
   "outputs": [],
   "source": [
    "# Example of creating new collection of data products with the \"dsm\" data type\n",
    "dsm_data_products = data_products.filter_by_data_type(\"dsm\")\n",
    "print(dsm_data_products)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 17
    },
    "id": "34",
    "outputId": "b90f75de-7c22-4edc-82a4-55e5df4e292a"
   },
   "outputs": [],
   "source": [
    "dsm_data = dsm_data_products[0]\n",
    "dsm_url = dsm_data.url\n",
    "dsm_url = leafmap.d2s_tile(dsm_url)\n",
    "m.add_cog_layer(dsm_url, colormap_name=\"terrain\", name=\"DSM\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57",
   "metadata": {
    "id": "35"
   },
   "source": [
    "Add a colorbar to the map."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 17
    },
    "id": "36",
    "outputId": "a83408c1-c53e-4542-9c23-224c36a67687"
   },
   "outputs": [],
   "source": [
    "vis_params = {\"palette\": \"terrain\", \"min\": 125, \"max\": 250}\n",
    "m.add_colorbar(vis_params, label=\"Elevation (m)\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "59",
   "metadata": {
    "id": "37"
   },
   "source": [
    "Add the project boundary to the map."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 17
    },
    "id": "38",
    "outputId": "1aac998f-949f-452d-fd38-514f66c49b2e"
   },
   "outputs": [],
   "source": [
    "m.add_geojson(project_boundary, layer_name=\"Purdue Campus\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61",
   "metadata": {},
   "source": [
    "Add LiDAR DEM hillshade, DTM, and NDHM to the map."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 621,
     "referenced_widgets": [
      "d1f170c3fd2e42288fe2cd579e201720",
      "ab035125ec184080beb5a81498dfd9a6",
      "970f91f4621047788d1c068f7a40a6cf",
      "2ce6ff6a498645fdbd6d8579e0d49e6b",
      "616c0f2cfe9549a1b6f67bfd7cc74a97",
      "101e315a189341b2aa4d1402cf527c40",
      "952f9cb0408541008597764fc527a038",
      "1b045b1b15ba4a64b81ad85f6a41a220",
      "f0bf73a8774a4da186520ac54ad0eae1",
      "11cfc171fcc04e1ea29064c4ffc03144",
      "c39030a97c314614a32bced01031d414",
      "02af050f42b649ef93536dd17e6ba7c1",
      "94c352fa63284f9abeaaff6b008c997c",
      "ecc708743f4c45df9033e0688c7c4d92",
      "977f9243eb9946fcabeaddb987dd485d",
      "72f5a6d4fce044c4afa70dbb6355202e",
      "c7a0fe40e37a46fd908489402c4a54d2",
      "b21cc49a9be94aaa8a1bebd25c89555f",
      "96c497c3e4824b5f9263b8c8c254518b",
      "4fd82da4c841471fb71bd2c759bfd0c6",
      "1f6a5007b6304cbfb8a2cac224b5d6c2",
      "ea04195319374795b693ee8f1245f355",
      "356d8a09ddd247dbb4f87454f74fd0b1",
      "02852dff26f844ada3692d05b6663cb8",
      "905c476a41c54f7e84074495922573d4",
      "b4e1bd3d9da5424b89f6ee232b30cbd8",
      "540a9c56b8614076bd2891710c5b9724",
      "e343f8a4f5684e0daa282c4b0b55d45d",
      "f4f7f63d49b44486b1e13648e04c28c3",
      "74a581dc5b444030ba2b84c80a9d20bf",
      "6ec0907b72b946cc9122ed0426460f43",
      "c11677a475ed41ffa17ac2f81dca0454",
      "0df61538421d4c05a81ec8434b375a12",
      "21c4c411178347c6bfe7763edfd47a15",
      "0d74cd61a0fd42598e9c78de72aa2688",
      "320051d2f7c64eea9c43ef25af858018",
      "daac2121414e413d9f518deadd3c6025",
      "a6ddf1b05f524c03931399fb3a1decd2",
      "c66a9f6abe3b44e19e4363907698b91a",
      "1ba46b24e84f4524abd25f8b3c84c37b",
      "8019f3e8738f429f8e156f990a749e40",
      "c1725e1106404cc5926d9f21ed7f2513",
      "aa08d9e23bc24dbd97bdd908985c9173",
      "ec72d0ff56b84e74b08eeaed8151544f",
      "bc5d3ac187904dc1820a5ae0caafb0fd",
      "40ef0855ebaa47d996bb0862ec16d028",
      "0b04ab4d00c641cd9ad8a47bf06c1788",
      "409d9f61852446b7abb07ebedbb210db",
      "8c88fba89d4d4a489cc932f542397f1d",
      "952c1550d663410a8bb16b13abb6f12b",
      "58c45e4196984ef4ac2702917d2aeb79",
      "94968976c7ed416aa345082485baf2d5",
      "c2423fa673e4497bbd203fd84df05f25",
      "a6d8623793ca4e2f809210daee8940d1",
      "e6820722d478428ca2d6189614c5221f",
      "3efb936fe47b49c1a48f9a8522e82c02",
      "7a8d5713fcbe4c8890c77e250f01a8ee",
      "0c7a8aacac644547a12fecd50a372553",
      "cb42ab9f11754694b52fb9dff9e97f77",
      "bbd84cac27d04ced9cb63f7b14bfdb82",
      "1ada50bd4fcc43348722bf766721e8c5",
      "caad630198664301b797465634b8dc4a",
      "402d4017d68844958be317ed3a5ca7c4",
      "077c8df27c634b479b3f81ca89b41ce3",
      "8c25730c5b944f00ab08df2aebb59a74",
      "addd3118556d4468bca7268a43668c8b",
      "50652babd16945bfb0349c199adf57cb",
      "6f921a2acbed4e3786668387cedea61a",
      "cca3b39b2bda44e79f39df333c89b0c9",
      "b6e67215762b47b697070323af432e5d",
      "c5af07b54b3147f0a792d9537ba58ca6",
      "483a64998bc24db6bebd25b123ead0df",
      "41b1255285e841159677067a56b60fe3",
      "33ec6b4b693040cb8e967cbc84e511b4",
      "47118cfaa88347aca1aa25181f2e063f",
      "c1167c398d75425f97957be2a2e64db3",
      "75529c5245b34b1c878daded8017687c",
      "74d3d1244cd8409782961fe467a1d2dd",
      "c26e31d772d6435ea1e0d71b85bb17f5",
      "9de3cbafa3644ea5bac73305718cd241",
      "f04304bf9dab436b84d2f11ff24fb5a6",
      "38556cf95fd949c9bcb159f60ad4f616",
      "a2827ec9442d47e686fc265e168e46c9",
      "f939594110af41dbb7f271cf556b6dde",
      "b31686b8401b4e1a901829a99ad33d2f",
      "2d23439c8cb842b88de64948fa1f416b",
      "b7a98743061a46488de468617ab399c5",
      "9eb95357c8044accb45773de0b23404e",
      "0c85b191271a4548864356ca2fe10941",
      "a510c33e7e1b486e82a370572b36a776",
      "07c198b1add640e6bc477220d08865b9",
      "eabdcb7686654a3285d73fbd22620920",
      "55e13d631c7e4d46893a17b61f94aaad",
      "405326e123aa4f9d9e788c760480b378",
      "85d261d0a12a4bba9538162e95f124d8",
      "c8086106c31542d085915fd7bb5b17e6",
      "9926f89dc4854afc9229e3e39cd66e81",
      "e901940ef65347e0af2afcb5ab4eb8a4",
      "d3105af5474a4d958769288e40ea1d53",
      "f7e8f65c98824f92b14226bc67f53913",
      "792a3558edfa405ba9648e22420c1d9b",
      "a5c6d57304ce40aba4dc53f2a698ec60",
      "0e66b15002c047948b90c0bf5d9f06db",
      "fbf3309b97b94749aeb13ac990c9afd0",
      "626b47c79b504caf905645409bef1037",
      "caab8e7743fe4659ac0b41c834fe1bf3",
      "2c2a629523bd4aa79efb53a1541d5eb4",
      "fde7a9417b084051a82b7bc597af3f4f",
      "405013c6c6c64ed3b25a7dc0aca380d9",
      "48f1b38f56a649d7becfa5335c47be37",
      "4fa9a89152df46fda51c9fc88d3031d7",
      "fc5445348c954dccb74b5545aff7736e",
      "c614a6e213c54525aa1efc94e59e16f2",
      "bfd735d029a64482b7285da9a26d71d6",
      "dba824c93bc34eae89cb0ec4d62de501",
      "8cf6a39d031f4bcf8689e3424739af83",
      "06bc80ae21674c9d82aca884b4ffffea",
      "9b5ce560154345b2b3c17c62464c6fab",
      "a28ad0ce14ff443cbc15ac424cf98968",
      "1839388233fb4558b5ae6cfb4a7028df",
      "6ab4f49d23ba4159aa5309e47f008315",
      "8da799c6f0964de8be9b0f99b35b9a12",
      "6cc7a0fa0b0d49068ac081ffc723145b"
     ]
    },
    "id": "39",
    "outputId": "f332a226-1151-44b4-ad96-dfc7d2075353"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "basemap_url = \"https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}\"\n",
    "m.add_tile_layer(basemap_url, name=\"Google Hybrid\", attribution=\"Google\", shown=False)\n",
    "hs_data_products = data_products.filter_by_data_type(\"DTM HS\")\n",
    "hs_data = hs_data_products[0]\n",
    "hs_url = hs_data.url\n",
    "hs_url = leafmap.d2s_tile(hs_url)\n",
    "dtm_data_products = data_products.filter_by_data_type(\"DTM\")\n",
    "dtm_data = dtm_data_products[0]\n",
    "dtm_url = dtm_data.url\n",
    "dtm_url = leafmap.d2s_tile(dtm_url)\n",
    "ndhm_data_products = data_products.filter_by_data_type(\"NDHM\")\n",
    "ndhm_data = ndhm_data_products[0]\n",
    "ndhm_url = ndhm_data.url\n",
    "ndhm_url = leafmap.d2s_tile(ndhm_url)\n",
    "m.add_cog_layer(hs_url, name=\"Hillshade\")\n",
    "m.add_cog_layer(dtm_url, colormap_name=\"terrain\", name=\"DTM\", opacity=0.5)\n",
    "m.add_cog_layer(ndhm_url, colormap_name=\"terrain\", name=\"CHM\", shown=False)\n",
    "m.add_colorbar(vis_params, label=\"Elevation (m)\")\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "63",
   "metadata": {},
   "source": [
    "Retrieve the Ortho data product for the 2023 flight."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "64",
   "metadata": {},
   "outputs": [],
   "source": [
    "flight_2023 = filtered_flights[1]\n",
    "data_products = flight_2023.get_data_products()\n",
    "ortho_data_products = data_products.filter_by_data_type(\"ortho\")\n",
    "ortho_data = ortho_data_products[0]\n",
    "ortho_url_2123 = ortho_data.url\n",
    "ortho_url_2023 = leafmap.d2s_tile(ortho_url_2123)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "65",
   "metadata": {},
   "source": [
    "Create a split map for comparing the 2018 and 2023 ortho images."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66",
   "metadata": {},
   "outputs": [],
   "source": [
    "from ipyleaflet import TileLayer\n",
    "\n",
    "m = geemap.Map()\n",
    "left_layer = TileLayer(url=geemap.cog_tile(ortho_url), name=\"2018 Ortho\")\n",
    "right_layer = TileLayer(url=geemap.cog_tile(ortho_url_2023), name=\"2023 Ortho\")\n",
    "m.split_map(left_layer, right_layer)\n",
    "m.set_center(-86.9048, 40.4247, 15)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67",
   "metadata": {
    "id": "40"
   },
   "source": [
    "## Using Earth Engine data\n",
    "\n",
    "### Earth Engine data types\n",
    "\n",
    "Earth Engine objects are server-side objects rather than client-side objects, which means that they are not stored locally on your computer. Similar to video streaming services (e.g., YouTube, Netflix, and Hulu), which store videos/movies on their servers, Earth Engine data are stored on the Earth Engine servers. We can stream geospatial data from Earth Engine on-the-fly without having to download the data just like we can watch videos from streaming services using a web browser without having to download the entire video to your computer.\n",
    "\n",
    "-   **Image**: the fundamental raster data type in Earth Engine.\n",
    "-   **ImageCollection**: a stack or time-series of images.\n",
    "-   **Geometry**: the fundamental vector data type in Earth Engine.\n",
    "-   **Feature**: a Geometry with attributes.\n",
    "-   **FeatureCollection**: a set of features.\n",
    "\n",
    "### Image\n",
    "\n",
    "Raster data in Earth Engine are represented as **Image** objects. Images are composed of one or more bands and each band has its own name, data type, scale, mask and projection. Each image has metadata stored as a set of properties.\n",
    "\n",
    "#### Loading Earth Engine images"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "68",
   "metadata": {
    "id": "41"
   },
   "outputs": [],
   "source": [
    "image = ee.Image(\"USGS/SRTMGL1_003\")\n",
    "image"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69",
   "metadata": {
    "id": "42"
   },
   "source": [
    "#### Visualizing Earth Engine images"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "70",
   "metadata": {
    "id": "43"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "image = ee.Image(\"USGS/SRTMGL1_003\")\n",
    "vis_params = {\n",
    "    \"min\": 0,\n",
    "    \"max\": 4000,\n",
    "    \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],  # 'terrain'\n",
    "}\n",
    "m.add_layer(image, vis_params, \"SRTM\")\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "71",
   "metadata": {
    "id": "44"
   },
   "outputs": [],
   "source": [
    "roi = ee.FeatureCollection(geemap.geojson_to_ee(project_boundary))\n",
    "roi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72",
   "metadata": {
    "id": "45"
   },
   "outputs": [],
   "source": [
    "m.add_layer(roi, {}, \"Purdue Campus\")\n",
    "m.centerObject(roi, 15)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73",
   "metadata": {
    "id": "46"
   },
   "outputs": [],
   "source": [
    "hillshade = ee.Terrain.hillshade(image).clipToCollection(roi)\n",
    "m.add_layer(hillshade, {}, \"SRTM Hillshade\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74",
   "metadata": {
    "id": "47"
   },
   "source": [
    "### ImageCollection\n",
    "\n",
    "An `ImageCollection` is a stack or sequence of images. An `ImageCollection` can be loaded by passing an Earth Engine asset ID into the `ImageCollection` constructor. You can find `ImageCollection` IDs in the [Earth Engine Data Catalog](https://developers.google.com/earth-engine/datasets).\n",
    "\n",
    "#### Loading image collections\n",
    "\n",
    "For example, to load the image collection of the [Sentinel-2 surface reflectance](https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR_HARMONIZED):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "75",
   "metadata": {
    "id": "48"
   },
   "outputs": [],
   "source": [
    "collection = ee.ImageCollection(\"COPERNICUS/S2_SR_HARMONIZED\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "76",
   "metadata": {
    "id": "49"
   },
   "source": [
    "#### Visualizing image collections\n",
    "\n",
    "To visualize an Earth Engine **ImageCollection**, we need to convert an **ImageCollection** to an **Image** by compositing all the images in the collection to a single image representing, for example, the min, max, median, mean or standard deviation of the images. For example, to create a median value image from a collection, use the `collection.median()` method. Let's create a median image from the Sentinel-2 surface reflectance collection:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77",
   "metadata": {
    "id": "50"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "collection = (\n",
    "    ee.ImageCollection(\"COPERNICUS/S2_SR_HARMONIZED\")\n",
    "    .filterDate(\"2023-01-01\", \"2024-08-01\")\n",
    "    .filter(ee.Filter.lt(\"CLOUDY_PIXEL_PERCENTAGE\", 5))\n",
    ")\n",
    "image = collection.median().clipToCollection(roi)\n",
    "\n",
    "vis = {\n",
    "    \"min\": 0.0,\n",
    "    \"max\": 2500,\n",
    "    \"bands\": [\"B4\", \"B3\", \"B2\"],\n",
    "}\n",
    "\n",
    "m.add_layer(image, vis, \"Sentinel-2\")\n",
    "m.centerObject(roi, 15)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "78",
   "metadata": {
    "id": "51"
   },
   "source": [
    "### FeatureCollection\n",
    "\n",
    "A **FeatureCollection** is a collection of Features. A FeatureCollection is analogous to a GeoJSON FeatureCollection object, i.e., a collection of features with associated properties/attributes. Data contained in a shapefile can be represented as a FeatureCollection.\n",
    "\n",
    "#### Loading feature collections\n",
    "\n",
    "The [Earth Engine Data Catalog](https://developers.google.com/earth-engine/datasets) hosts a variety of vector datasets (e.g,, US Census data, country boundaries, and more) as feature collections. You can find feature collection IDs by searching the data catalog. For example, to load the [TIGER roads data](https://developers.google.com/earth-engine/datasets/catalog/TIGER_2016_Roads) by the U.S. Census Bureau:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "79",
   "metadata": {
    "id": "52"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "fc = ee.FeatureCollection(\"TIGER/2016/Roads\").filterBounds(roi)\n",
    "m.add_layer(fc, {}, \"Census roads\")\n",
    "m.centerObject(roi, 15)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80",
   "metadata": {
    "id": "53"
   },
   "source": [
    "#### Filtering feature collections\n",
    "\n",
    "* [geoBoundaries: Political administrative boundaries at Country level (ADM0)](https://developers.google.com/earth-engine/datasets/catalog/WM_geoLab_geoBoundaries_600_ADM0)\n",
    "* [geoBoundaries: Political administrative boundaries at District level (ADM1)](https://developers.google.com/earth-engine/datasets/catalog/WM_geoLab_geoBoundaries_600_ADM1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81",
   "metadata": {
    "id": "54"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map(center=[40, -100], zoom=4)\n",
    "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM0\")\n",
    "fc = countries.filter(ee.Filter.eq(\"shapeName\", \"United States\"))\n",
    "m.add_layer(fc, {}, \"USA\")\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "82",
   "metadata": {
    "id": "55"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map(center=[40, -100], zoom=4)\n",
    "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM1\")\n",
    "fc = countries.filter(ee.Filter.eq(\"shapeGroup\", \"USA\"))\n",
    "m.add_layer(fc, {}, \"USA\")\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83",
   "metadata": {
    "id": "56"
   },
   "source": [
    "#### Visualizing feature collections"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84",
   "metadata": {
    "id": "57"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM1\")\n",
    "fc = countries.filter(ee.Filter.eq(\"shapeGroup\", \"USA\"))\n",
    "style = {\"color\": \"000000ff\", \"width\": 2, \"lineType\": \"solid\", \"fillColor\": \"FF000000\"}\n",
    "m.add_layer(fc.style(**style), {}, \"USA\")\n",
    "m.center_object(fc, 4)\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85",
   "metadata": {
    "id": "58"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM1\")\n",
    "fc = countries.filter(ee.Filter.eq(\"shapeGroup\", \"USA\"))\n",
    "style = {\"color\": \"0000ffff\", \"width\": 2, \"lineType\": \"solid\", \"fillColor\": \"FF000080\"}\n",
    "m.add_layer(fc.style(**style), {}, \"USA\")\n",
    "m.center_object(fc, 4)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86",
   "metadata": {
    "id": "59"
   },
   "source": [
    "### Earth Engine Data Catalog\n",
    "\n",
    "The [Earth Engine Data Catalog](https://developers.google.com/earth-engine/datasets) hosts a variety of geospatial datasets. As of September 2024, the catalog contains over [1,100 datasets](https://github.com/opengeos/Earth-Engine-Catalog/blob/master/gee_catalog.tsv) with a total size of over 100 petabytes. Some notable datasets include: Landsat, Sentinel, MODIS, NAIP, etc. For a complete list of datasets in CSV or JSON formats, see the [Earth Engine Datasets List](https://github.com/giswqs/Earth-Engine-Catalog/blob/master/gee_catalog.tsv).\n",
    "\n",
    "#### Searching for datasets\n",
    "\n",
    "The [Earth Engine Data Catalog](https://developers.google.com/earth-engine/datasets/catalog) is searchable. You can search datasets by name, keyword, or tag. For example, enter \"elevation\" in the search box will filter the catalog to show only datasets containing \"elevation\" in their name, description, or tags. 52 datasets are returned for this search query. Scroll down the list to find the [NASA SRTM Digital Elevation 30m](https://developers.google.com/earth-engine/datasets/catalog/USGS_SRTMGL1_003#description) dataset. On each dataset page, you can find the following information, including Dataset Availability, Dataset Provider, Earth Engine Snippet, Tags, Description, Code Example, and more. One important piece of information is the Image/ImageCollection/FeatureCollection ID of each dataset, which is essential for accessing the dataset through the Earth Engine JavaScript or Python APIs.\n",
    "\n",
    "![](https://i.imgur.com/B3rf4QN.jpg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87",
   "metadata": {
    "id": "60"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88",
   "metadata": {
    "id": "61"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "dem = ee.Image(\"USGS/SRTMGL1_003\")\n",
    "vis_params = {\n",
    "    \"min\": 0,\n",
    "    \"max\": 4000,\n",
    "    \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],\n",
    "}\n",
    "m.add_layer(dem, vis_params, \"SRTM DEM\")\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89",
   "metadata": {
    "id": "62"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "counties = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM0\")\n",
    "fc = counties.filter(ee.Filter.eq(\"shapeName\", \"United States\"))\n",
    "dem = ee.Image(\"USGS/SRTMGL1_003\").clipToCollection(fc)\n",
    "vis_params = {\n",
    "    \"min\": 0,\n",
    "    \"max\": 4000,\n",
    "    \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],\n",
    "}\n",
    "\n",
    "m.add_layer(fc, {}, \"United States\")\n",
    "m.add_layer(dem, vis_params, \"SRTM DEM\")\n",
    "m.center_object(fc, 4)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "90",
   "metadata": {
    "id": "63"
   },
   "source": [
    "## Visualizing Earth Engine data\n",
    "\n",
    "### Using the inspector tool\n",
    "\n",
    "Inspect pixel values and vector features using the inspector tool."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "91",
   "metadata": {
    "id": "64"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "\n",
    "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM1\")\n",
    "fc = countries.filter(ee.Filter.eq(\"shapeGroup\", \"USA\"))\n",
    "\n",
    "dem = ee.Image(\"USGS/SRTMGL1_003\")\n",
    "landsat7 = ee.Image(\"LANDSAT/LE7_TOA_5YEAR/1999_2003\").select(\n",
    "    [\"B1\", \"B2\", \"B3\", \"B4\", \"B5\", \"B7\"]\n",
    ")\n",
    "\n",
    "vis_params = {\n",
    "    \"min\": 0,\n",
    "    \"max\": 4000,\n",
    "    \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],\n",
    "}\n",
    "\n",
    "m.add_layer(\n",
    "    landsat7,\n",
    "    {\"bands\": [\"B4\", \"B3\", \"B2\"], \"min\": 20, \"max\": 200, \"gamma\": 2.0},\n",
    "    \"Landsat 7\",\n",
    ")\n",
    "m.add_layer(dem, vis_params, \"SRTM DEM\")\n",
    "m.add_layer(fc, {}, \"United States\")\n",
    "m.add(\"inspector\")\n",
    "m.center_object(fc, 4)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "92",
   "metadata": {
    "id": "65"
   },
   "source": [
    "### Using the plotting tool\n",
    "\n",
    "Plot spectral profiles of pixels using the plotting tool."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "93",
   "metadata": {
    "id": "66"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map(center=[40, -100], zoom=4)\n",
    "\n",
    "landsat7 = ee.Image(\"LANDSAT/LE7_TOA_5YEAR/1999_2003\").select(\n",
    "    [\"B1\", \"B2\", \"B3\", \"B4\", \"B5\", \"B7\"]\n",
    ")\n",
    "\n",
    "landsat_vis = {\"bands\": [\"B4\", \"B3\", \"B2\"], \"gamma\": 1.4}\n",
    "m.add_layer(landsat7, landsat_vis, \"Landsat\")\n",
    "\n",
    "hyperion = ee.ImageCollection(\"EO1/HYPERION\").filter(\n",
    "    ee.Filter.date(\"2016-01-01\", \"2017-03-01\")\n",
    ")\n",
    "\n",
    "hyperion_vis = {\n",
    "    \"min\": 1000.0,\n",
    "    \"max\": 14000.0,\n",
    "    \"gamma\": 2.5,\n",
    "}\n",
    "m.add_layer(hyperion, hyperion_vis, \"Hyperion\")\n",
    "m.add_plot_gui()\n",
    "m.center_object(fc, 4)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "94",
   "metadata": {
    "id": "67"
   },
   "source": [
    "Set plotting options for Landsat."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95",
   "metadata": {
    "id": "68"
   },
   "outputs": [],
   "source": [
    "m.set_plot_options(add_marker_cluster=True, overlay=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "96",
   "metadata": {
    "id": "69"
   },
   "source": [
    "Set plotting options for Hyperion."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "97",
   "metadata": {
    "id": "70"
   },
   "outputs": [],
   "source": [
    "m.set_plot_options(add_marker_cluster=True, plot_type=\"bar\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "98",
   "metadata": {
    "id": "71"
   },
   "source": [
    "### Legends, color bars, and labels\n",
    "\n",
    "#### Built-in legends"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99",
   "metadata": {
    "id": "72"
   },
   "outputs": [],
   "source": [
    "from geemap.legends import builtin_legends"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "100",
   "metadata": {
    "id": "73"
   },
   "outputs": [],
   "source": [
    "for legend in builtin_legends:\n",
    "    print(legend)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "101",
   "metadata": {
    "id": "74"
   },
   "source": [
    "Add ESA WorldCover and legend to the map.\n",
    "\n",
    "https://developers.google.com/earth-engine/datasets/catalog/ESA_WorldCover_v200"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "102",
   "metadata": {
    "id": "75"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "m.add_basemap(\"Esri.WorldImagery\")\n",
    "\n",
    "dataset = ee.ImageCollection(\"ESA/WorldCover/v200\").first()\n",
    "visualization = {\"bands\": [\"Map\"]}\n",
    "m.add_layer(dataset, visualization, \"Landcover\")\n",
    "m.add_layer(fc, {}, \"United States\")\n",
    "m.add_legend(title=\"Land Cover Type\", builtin_legend=\"ESA_WorldCover\")\n",
    "m.center_object(fc, 4)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "103",
   "metadata": {
    "id": "76"
   },
   "source": [
    "#### Custom legends"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "104",
   "metadata": {
    "id": "77"
   },
   "source": [
    "Add a custom legend by specifying a dictionary of colors and labels."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "105",
   "metadata": {
    "id": "78"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "m.add_basemap(\"Esri.WorldImagery\")\n",
    "\n",
    "dataset = ee.ImageCollection(\"ESA/WorldCover/v200\").first()\n",
    "visualization = {\"bands\": [\"Map\"]}\n",
    "m.add_layer(dataset, visualization, \"Landcover\")\n",
    "m.add_layer(fc, {}, \"United States\")\n",
    "legend_dict = {\n",
    "    \"10 Trees\": \"006400\",\n",
    "    \"20 Shrubland\": \"ffbb22\",\n",
    "    \"30 Grassland\": \"ffff4c\",\n",
    "    \"40 Cropland\": \"f096ff\",\n",
    "    \"50 Built-up\": \"fa0000\",\n",
    "    \"60 Barren / sparse vegetation\": \"b4b4b4\",\n",
    "    \"70 Snow and ice\": \"f0f0f0\",\n",
    "    \"80 Open water\": \"0064c8\",\n",
    "    \"90 Herbaceous wetland\": \"0096a0\",\n",
    "    \"95 Mangroves\": \"00cf75\",\n",
    "    \"100 Moss and lichen\": \"fae6a0\",\n",
    "}\n",
    "m.add_legend(title=\"Land Cover Type\", legend_dict=legend_dict)\n",
    "m.center_object(fc, 4)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "106",
   "metadata": {
    "id": "79"
   },
   "source": [
    "#### Creating color bars\n",
    "\n",
    "Add a horizontal color bar."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "107",
   "metadata": {
    "id": "80"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM0\")\n",
    "fc = countries.filter(ee.Filter.eq(\"shapeName\", \"United States\"))\n",
    "dem = ee.Image(\"USGS/SRTMGL1_003\").clipToCollection(fc)\n",
    "vis_params = {\n",
    "    \"min\": 0,\n",
    "    \"max\": 4000,\n",
    "    \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],\n",
    "}\n",
    "\n",
    "m.add_layer(dem, vis_params, \"SRTM DEM\")\n",
    "m.add_colorbar(vis_params, label=\"Elevation (m)\", layer_name=\"SRTM DEM\")\n",
    "m.center_object(fc, 4)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "108",
   "metadata": {
    "id": "81"
   },
   "source": [
    "Add a vertical color bar."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "109",
   "metadata": {
    "id": "82"
   },
   "outputs": [],
   "source": [
    "m.add_colorbar(\n",
    "    vis_params,\n",
    "    label=\"Elevation (m)\",\n",
    "    layer_name=\"SRTM DEM\",\n",
    "    orientation=\"vertical\",\n",
    "    max_width=\"100px\",\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "110",
   "metadata": {
    "id": "83"
   },
   "source": [
    "Make the color bar background transparent."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "111",
   "metadata": {
    "id": "84"
   },
   "outputs": [],
   "source": [
    "m.add_colorbar(\n",
    "    vis_params,\n",
    "    label=\"Elevation (m)\",\n",
    "    layer_name=\"SRTM DEM\",\n",
    "    orientation=\"vertical\",\n",
    "    max_width=\"100px\",\n",
    "    transparent_bg=True,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "112",
   "metadata": {
    "id": "85"
   },
   "source": [
    "### Split-panel maps\n",
    "\n",
    "Create a split map with basemaps. Note that ipyleaflet has a bug with the SplitControl. You can't pan the map, which should be resolved in the next ipyleaflet release."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "113",
   "metadata": {
    "id": "86"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "m.split_map(left_layer=\"Esri.WorldTopoMap\", right_layer=\"OpenTopoMap\")\n",
    "m.center_object(roi, 6)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "114",
   "metadata": {
    "id": "87"
   },
   "source": [
    "Create a split map with Earth Engine layers."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "115",
   "metadata": {
    "id": "88"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "\n",
    "esa_2020 = ee.ImageCollection(\"ESA/WorldCover/v100\").first()\n",
    "esa_2021 = ee.ImageCollection(\"ESA/WorldCover/v200\").first()\n",
    "visualization = {\"bands\": [\"Map\"]}\n",
    "\n",
    "left_layer = geemap.ee_tile_layer(esa_2020, visualization, \"Land Cover 2020\")\n",
    "right_layer = geemap.ee_tile_layer(esa_2021, visualization, \"Land Cover 2021\")\n",
    "\n",
    "m.split_map(\n",
    "    left_layer, right_layer, left_label=\"Land Cover 2020\", right_label=\"Land Cover 2021\"\n",
    ")\n",
    "m.add_legend(title=\"Land Cover Type\", builtin_legend=\"ESA_WorldCover\")\n",
    "m.center_object(fc, 4)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "116",
   "metadata": {
    "id": "89"
   },
   "source": [
    "### Timeseries inspector and time slider\n",
    "\n",
    "#### Timeseries inspector\n",
    "\n",
    "Check the available years of NLCD."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "117",
   "metadata": {
    "id": "90"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map(center=[40, -100], zoom=4)\n",
    "collection = ee.ImageCollection(\"USGS/NLCD_RELEASES/2019_REL/NLCD\").select(\"landcover\")\n",
    "vis_params = {\"bands\": [\"landcover\"]}\n",
    "years = collection.aggregate_array(\"system:index\").getInfo()\n",
    "years"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "118",
   "metadata": {
    "id": "91"
   },
   "source": [
    "Create a timeseries inspector for NLCD. Note that ipyleaflet has a bug with the SplitControl. You can't pan the map, which should be resolved in a future ipyleaflet release."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "119",
   "metadata": {
    "id": "92"
   },
   "outputs": [],
   "source": [
    "m.ts_inspector(\n",
    "    left_ts=collection,\n",
    "    right_ts=collection,\n",
    "    left_names=years,\n",
    "    right_names=years,\n",
    "    left_vis=vis_params,\n",
    "    right_vis=vis_params,\n",
    "    width=\"80px\",\n",
    ")\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "120",
   "metadata": {},
   "source": [
    "Generate the NAIP timeseries."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "121",
   "metadata": {},
   "outputs": [],
   "source": [
    "naip_col = geemap.naip_timeseries(roi, RGBN=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "122",
   "metadata": {},
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "vis_params = {\"bands\": [\"N\", \"R\", \"G\"]}\n",
    "m.ts_inspector(naip_col, left_vis=vis_params, date_format=\"YYYY\", width=\"80px\")\n",
    "m.center_object(roi, 15)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "123",
   "metadata": {
    "id": "93"
   },
   "source": [
    "#### Time slider\n",
    "\n",
    "Note that this feature may not work properly with in the Colab environment. Restart Colab runtime if the time slider does not work.\n",
    "\n",
    "Create a map for visualizing MODIS vegetation data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "124",
   "metadata": {
    "id": "94"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "\n",
    "collection = (\n",
    "    ee.ImageCollection(\"MODIS/MCD43A4_006_NDVI\")\n",
    "    .filter(ee.Filter.date(\"2022-06-01\", \"2022-07-01\"))\n",
    "    .select(\"NDVI\")\n",
    ")\n",
    "vis_params = {\n",
    "    \"min\": 0.0,\n",
    "    \"max\": 1.0,\n",
    "    \"palette\": \"ndvi\",\n",
    "}\n",
    "\n",
    "m.add_time_slider(collection, vis_params, time_interval=2)\n",
    "m._toolbar.toggle_layers(False)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "125",
   "metadata": {
    "id": "95"
   },
   "source": [
    "Create a map for visualizing weather data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "126",
   "metadata": {
    "id": "96"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "\n",
    "collection = (\n",
    "    ee.ImageCollection(\"NOAA/GFS0P25\")\n",
    "    .filterDate(\"2018-12-22\", \"2018-12-23\")\n",
    "    .limit(24)\n",
    "    .select(\"temperature_2m_above_ground\")\n",
    ")\n",
    "\n",
    "vis_params = {\n",
    "    \"min\": -40.0,\n",
    "    \"max\": 35.0,\n",
    "    \"palette\": [\"blue\", \"purple\", \"cyan\", \"green\", \"yellow\", \"red\"],\n",
    "}\n",
    "\n",
    "labels = [str(n).zfill(2) + \":00\" for n in range(0, 24)]\n",
    "m.add_time_slider(collection, vis_params, labels=labels, time_interval=1, opacity=0.8)\n",
    "m._toolbar.toggle_layers(False)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "127",
   "metadata": {
    "id": "97"
   },
   "source": [
    "Visualizing Sentinel-2 imagery"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "128",
   "metadata": {
    "id": "98"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "\n",
    "collection = (\n",
    "    ee.ImageCollection(\"COPERNICUS/S2_SR_HARMONIZED\")\n",
    "    .filterBounds(roi)\n",
    "    .filterMetadata(\"CLOUDY_PIXEL_PERCENTAGE\", \"less_than\", 0.5)\n",
    ")\n",
    "\n",
    "vis_params = {\"min\": 0, \"max\": 4000, \"bands\": [\"B8\", \"B4\", \"B3\"]}\n",
    "m.center_object(roi, 14)\n",
    "m.add_time_slider(collection, vis_params, region=roi)\n",
    "m._toolbar.toggle_layers(False)\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "129",
   "metadata": {
    "id": "99"
   },
   "source": [
    "## Analyzing Earth Engine data\n",
    "\n",
    "### Zonal statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "130",
   "metadata": {
    "id": "100"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map(center=[40, -100], zoom=4)\n",
    "\n",
    "# Add NASA SRTM\n",
    "dem = ee.Image(\"USGS/SRTMGL1_003\")\n",
    "dem_vis = {\n",
    "    \"min\": 0,\n",
    "    \"max\": 4000,\n",
    "    \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],\n",
    "}\n",
    "m.add_layer(dem, dem_vis, \"SRTM DEM\")\n",
    "\n",
    "# Add 5-year Landsat TOA composite\n",
    "landsat = ee.Image(\"LANDSAT/LE7_TOA_5YEAR/1999_2003\")\n",
    "landsat_vis = {\"bands\": [\"B4\", \"B3\", \"B2\"], \"gamma\": 1.4}\n",
    "m.add_layer(landsat, landsat_vis, \"Landsat\", False)\n",
    "\n",
    "# Add US Census States\n",
    "fc = ee.FeatureCollection(\"TIGER/2018/States\")\n",
    "style = {\"fillColor\": \"00000000\"}\n",
    "m.add_layer(fc.style(**style), {}, \"US States\")\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "131",
   "metadata": {
    "id": "101"
   },
   "outputs": [],
   "source": [
    "out_dem_stats = \"dem_stats.csv\"\n",
    "geemap.zonal_stats(dem, fc, out_dem_stats, stat_type=\"MEAN\", return_fc=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "132",
   "metadata": {
    "id": "102"
   },
   "outputs": [],
   "source": [
    "df = geemap.csv_to_df(out_dem_stats).sort_values(by=[\"mean\"])\n",
    "df.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "133",
   "metadata": {
    "id": "103"
   },
   "outputs": [],
   "source": [
    "geemap.bar_chart(out_dem_stats, \"STUSPS\", \"mean\", title=\"Mean Elevation (m)\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "134",
   "metadata": {
    "id": "104"
   },
   "outputs": [],
   "source": [
    "out_landsat_stats = \"landsat_stats.csv\"\n",
    "geemap.zonal_stats(\n",
    "    landsat,\n",
    "    fc,\n",
    "    out_landsat_stats,\n",
    "    stat_type=\"MEAN\",\n",
    "    return_fc=False,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "135",
   "metadata": {
    "id": "105"
   },
   "outputs": [],
   "source": [
    "df = geemap.csv_to_df(out_landsat_stats)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "136",
   "metadata": {
    "id": "106"
   },
   "source": [
    "### Zonal statistics by group"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "137",
   "metadata": {
    "id": "107"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "m.add_basemap(\"Esri.WorldImagery\")\n",
    "fc = ee.FeatureCollection(\"TIGER/2018/States\")\n",
    "dataset = ee.ImageCollection(\"ESA/WorldCover/v200\").first().clipToCollection(fc)\n",
    "visualization = {\"bands\": [\"Map\"]}\n",
    "m.add_layer(dataset, visualization, \"Landcover\")\n",
    "m.add_legend(title=\"Land Cover Type\", builtin_legend=\"ESA_WorldCover\")\n",
    "m.add_layer(fc, {}, \"United States\")\n",
    "m.center_object(fc, 4)\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "138",
   "metadata": {
    "id": "108"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map(center=[40, -100], zoom=4)\n",
    "\n",
    "# Add NLCD data\n",
    "dataset = ee.Image(\"USGS/NLCD_RELEASES/2021_REL/NLCD/2021\")\n",
    "landcover = dataset.select(\"landcover\")\n",
    "m.add_layer(landcover, {}, \"NLCD 2021\")\n",
    "\n",
    "# Add US census states\n",
    "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
    "style = {\"fillColor\": \"00000000\"}\n",
    "m.add_layer(states.style(**style), {}, \"US States\")\n",
    "\n",
    "# Add NLCD legend\n",
    "m.add_legend(title=\"NLCD Land Cover\", builtin_legend=\"NLCD\")\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "139",
   "metadata": {
    "id": "109"
   },
   "outputs": [],
   "source": [
    "nlcd_stats = \"nlcd_stats.csv\"\n",
    "\n",
    "geemap.zonal_stats_by_group(\n",
    "    landcover,\n",
    "    states,\n",
    "    nlcd_stats,\n",
    "    stat_type=\"SUM\",\n",
    "    denominator=1e6,\n",
    "    decimal_places=2,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "140",
   "metadata": {},
   "outputs": [],
   "source": [
    "geemap.csv_to_df(nlcd_stats)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "141",
   "metadata": {
    "id": "111"
   },
   "outputs": [],
   "source": [
    "nlcd_stats = \"nlcd_stats_pct.csv\"\n",
    "\n",
    "geemap.zonal_stats_by_group(\n",
    "    landcover,\n",
    "    states,\n",
    "    nlcd_stats,\n",
    "    stat_type=\"PERCENTAGE\",\n",
    "    denominator=1e6,\n",
    "    decimal_places=2,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "142",
   "metadata": {},
   "outputs": [],
   "source": [
    "geemap.csv_to_df(nlcd_stats)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "143",
   "metadata": {
    "id": "112"
   },
   "source": [
    "## Creating timelapse animations\n",
    "\n",
    "### Landsat timelapse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "144",
   "metadata": {
    "id": "113"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map(center=[40, -100], zoom=4)\n",
    "m.add_basemap(\"Esri.WorldImagery\")\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "145",
   "metadata": {
    "id": "114"
   },
   "outputs": [],
   "source": [
    "roi = m.user_roi\n",
    "if roi is None:\n",
    "    roi = ee.Geometry.BBox(-86.9561, 40.4042, -86.8876, 40.4345)\n",
    "    m.add_layer(roi)\n",
    "    m.center_object(roi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "146",
   "metadata": {
    "id": "115"
   },
   "outputs": [],
   "source": [
    "timelapse = geemap.landsat_timelapse(\n",
    "    roi,\n",
    "    out_gif=\"West_Lafayette.gif\",\n",
    "    start_year=1988,\n",
    "    end_year=2024,\n",
    "    start_date=\"01-01\",\n",
    "    end_date=\"12-31\",\n",
    "    bands=[\"SWIR1\", \"NIR\", \"Red\"],\n",
    "    frames_per_second=5,\n",
    "    title=\"River Dynamics\",\n",
    "    progress_bar_color=\"blue\",\n",
    "    mp4=True,\n",
    ")\n",
    "geemap.show_image(timelapse)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "147",
   "metadata": {
    "id": "116"
   },
   "outputs": [],
   "source": [
    "roi = ee.Geometry.BBox(113.8252, 22.1988, 114.0851, 22.3497)\n",
    "timelapse = geemap.landsat_timelapse(\n",
    "    roi,\n",
    "    out_gif=\"hong_kong.gif\",\n",
    "    start_year=1990,\n",
    "    end_year=2022,\n",
    "    start_date=\"01-01\",\n",
    "    end_date=\"12-31\",\n",
    "    bands=[\"SWIR1\", \"NIR\", \"Red\"],\n",
    "    frames_per_second=3,\n",
    "    title=\"Hong Kong\",\n",
    ")\n",
    "geemap.show_image(timelapse)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "148",
   "metadata": {
    "id": "117"
   },
   "outputs": [],
   "source": [
    "roi = ee.Geometry.BBox(-115.5541, 35.8044, -113.9035, 36.5581)\n",
    "timelapse = geemap.landsat_timelapse(\n",
    "    roi,\n",
    "    out_gif=\"las_vegas.gif\",\n",
    "    start_year=1984,\n",
    "    end_year=2023,\n",
    "    bands=[\"NIR\", \"Red\", \"Green\"],\n",
    "    frames_per_second=5,\n",
    "    title=\"Las Vegas, NV\",\n",
    "    font_color=\"blue\",\n",
    ")\n",
    "geemap.show_image(timelapse)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "149",
   "metadata": {
    "id": "118"
   },
   "source": [
    "### Sentinel-2 timelapse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "150",
   "metadata": {
    "id": "119"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map(center=[-0.4315, -76.5748], zoom=13)\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "151",
   "metadata": {
    "id": "120"
   },
   "outputs": [],
   "source": [
    "roi = m.user_roi\n",
    "if roi is None:\n",
    "    roi = ee.Geometry.BBox(-86.9561, 40.4042, -86.8876, 40.4345)\n",
    "    m.add_layer(roi)\n",
    "    m.center_object(roi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "152",
   "metadata": {
    "id": "121"
   },
   "outputs": [],
   "source": [
    "timelapse = geemap.sentinel2_timelapse(\n",
    "    roi,\n",
    "    out_gif=\"sentinel2.gif\",\n",
    "    start_year=2017,\n",
    "    end_year=2024,\n",
    "    start_date=\"01-01\",\n",
    "    end_date=\"12-31\",\n",
    "    frequency=\"year\",\n",
    "    bands=[\"SWIR1\", \"NIR\", \"Red\"],\n",
    "    frames_per_second=3,\n",
    "    title=\"Sentinel-2 Timelapse\",\n",
    ")\n",
    "geemap.show_image(timelapse)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "153",
   "metadata": {
    "id": "122"
   },
   "source": [
    "### MODIS vegetation indices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "154",
   "metadata": {
    "id": "123"
   },
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "155",
   "metadata": {
    "id": "124"
   },
   "outputs": [],
   "source": [
    "roi = Map.user_roi\n",
    "if roi is None:\n",
    "    roi = ee.Geometry.BBox(-18.6983, -36.1630, 52.2293, 38.1446)\n",
    "    Map.addLayer(roi)\n",
    "    Map.centerObject(roi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "156",
   "metadata": {
    "id": "125"
   },
   "outputs": [],
   "source": [
    "timelapse = geemap.modis_ndvi_timelapse(\n",
    "    roi,\n",
    "    out_gif=\"ndvi.gif\",\n",
    "    data=\"Terra\",\n",
    "    band=\"NDVI\",\n",
    "    start_date=\"2000-01-01\",\n",
    "    end_date=\"2022-12-31\",\n",
    "    frames_per_second=3,\n",
    "    title=\"MODIS NDVI Timelapse\",\n",
    "    overlay_data=\"countries\",\n",
    ")\n",
    "geemap.show_image(timelapse)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "157",
   "metadata": {
    "id": "126"
   },
   "source": [
    "### GOES timelapse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "158",
   "metadata": {
    "id": "127"
   },
   "outputs": [],
   "source": [
    "roi = ee.Geometry.BBox(167.1898, -28.5757, 202.6258, -12.4411)\n",
    "start_date = \"2022-01-15T03:00:00\"\n",
    "end_date = \"2022-01-15T07:00:00\"\n",
    "data = \"GOES-17\"\n",
    "scan = \"full_disk\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "159",
   "metadata": {
    "id": "128"
   },
   "outputs": [],
   "source": [
    "timelapse = geemap.goes_timelapse(\n",
    "    roi, \"goes.gif\", start_date, end_date, data, scan, framesPerSecond=5\n",
    ")\n",
    "geemap.show_image(timelapse)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "160",
   "metadata": {
    "id": "129"
   },
   "outputs": [],
   "source": [
    "roi = ee.Geometry.BBox(-159.5954, 24.5178, -114.2438, 60.4088)\n",
    "start_date = \"2021-10-24T14:00:00\"\n",
    "end_date = \"2021-10-25T01:00:00\"\n",
    "data = \"GOES-17\"\n",
    "scan = \"full_disk\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "161",
   "metadata": {
    "id": "130"
   },
   "outputs": [],
   "source": [
    "timelapse = geemap.goes_timelapse(\n",
    "    roi, \"hurricane.gif\", start_date, end_date, data, scan, framesPerSecond=5\n",
    ")\n",
    "geemap.show_image(timelapse)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "162",
   "metadata": {
    "id": "131"
   },
   "outputs": [],
   "source": [
    "roi = ee.Geometry.BBox(-121.0034, 36.8488, -117.9052, 39.0490)\n",
    "start_date = \"2020-09-05T15:00:00\"\n",
    "end_date = \"2020-09-06T02:00:00\"\n",
    "data = \"GOES-17\"\n",
    "scan = \"full_disk\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "163",
   "metadata": {
    "id": "132"
   },
   "outputs": [],
   "source": [
    "timelapse = geemap.goes_fire_timelapse(\n",
    "    roi, \"fire.gif\", start_date, end_date, data, scan, framesPerSecond=5\n",
    ")\n",
    "geemap.show_image(timelapse)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "164",
   "metadata": {
    "id": "133"
   },
   "source": [
    "### Exercise - Creating timelapse animations\n",
    "\n",
    "Use the geemap timelapse GUI to create a timelapse animation for any location of your choice. Share the timelapse on social media and use the hashtag such as #EarthEngine and #geemap. See [this](https://i.imgur.com/YaCHvKC.gif) example.\n",
    "\n",
    "![](https://i.imgur.com/ohrXeFC.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "165",
   "metadata": {
    "id": "134"
   },
   "outputs": [],
   "source": [
    "m = geemap.Map()\n",
    "m.add_gui(\"timelapse\")\n",
    "m"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
